package com.wudi.estate.service.impl.ownermanagement;

import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wudi.estate.bean.ownermanagement.Personnel;
import com.wudi.estate.bean.ownermanagement.Pet;
import com.wudi.estate.mapper.ownermanagement.PersonnelMapper;
import com.wudi.estate.service.ownermanagement.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.Query;
import java.util.List;

@Service
public class PersonnelServiceImpl implements PersonnelService {
    @Autowired
    private PersonnelMapper personnelMapper;
    @Override
    public List<Personnel> selectAll() throws Exception {
        //无条件查询
        return personnelMapper.selectList(null);
    }

    @Override
    public Personnel selectById(Personnel p) throws Exception {
        return personnelMapper.selectById(p.getId());
    }

    @Override
    public Personnel selectById(long id) throws Exception {
        return personnelMapper.selectById(id);
    }

    @Override
    public void updateById(Personnel p) throws Exception {

        personnelMapper.updateById(p);
    }

    @Override
    public void updateStateById(Personnel p) throws Exception {
        Personnel personnel = personnelMapper.selectById(p.getId());
        if(personnel.isState()==true){
            personnel.setState(false);
        }

        personnelMapper.updateById(personnel);
    }

    @Override
    public void insert(Personnel p) throws Exception {

        personnelMapper.insert(p);
    }

    @Override
    public List<Personnel> selectByName(String name) throws Exception {
        QueryWrapper<Personnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name",name);
        return personnelMapper.selectList(queryWrapper);
    }
}
